package com.newgoldcurrency.activities.emailverifyandmodify;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import com.newgoldcurrency.databinding.ActivityEmailVerifyAndModifyBinding;

public class EmailVerifyAndModifyActivity extends AppCompatActivity {
    private ActivityEmailVerifyAndModifyBinding binding;
    private ActivityResultLauncher<Intent> launcher;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityEmailVerifyAndModifyBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.emailVerifyBack.setOnClickListener(v -> finish());
        binding.emailVerifyEmail.setOnClickListener(v -> {
            if (checkDoubleClick()){
                launcher.launch(new Intent(EmailVerifyAndModifyActivity.this, ModifyEmailActivity.class));
            }
        });
        binding.emailVerifyVerification.setOnClickListener(v -> {
            if (checkDoubleClick()){
                launcher.launch(new Intent(EmailVerifyAndModifyActivity.this, EmailVerificationActivity.class));
            }
        });
        launcher=registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
           if (result.getResultCode()==2)finish();
        });

    }
    private long mClickTime;
    private boolean checkDoubleClick() {
        boolean result= mClickTime < SystemClock.uptimeMillis() - 500;
        mClickTime = SystemClock.uptimeMillis();
        return result;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding=null;
    }
}